package com.uchiha.nova.mainService.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.dto.VisitorApplyInfoDTO;
import com.uchiha.nova.core.model.entity.VisitorApplyInfoEntity;
import com.uchiha.nova.core.model.query.VisitorApplyInfoQuery;
import com.uchiha.nova.core.model.vo.VisitorApplyInfoVO;
import com.uchiha.nova.core.tool.api.R;
import com.uchiha.nova.core.tool.constant.NovaCRUDMethodConstant;
import com.uchiha.nova.core.tool.support.BaseController;
import com.uchiha.nova.core.tool.support.Condition;
import com.uchiha.nova.core.tool.support.QueryContext;
import com.uchiha.nova.core.tool.util.Func;
import com.uchiha.nova.mainService.service.IVisitorApplyInfoService;
import com.uchiha.nova.mainService.wrapper.VisitorApplyInfoWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;



/**
 * 访问信息 控制器
 *
 * @author Uchihashiamu
 */
@RestController
@AllArgsConstructor
@RequestMapping("/visitorApplyInfo")
@Tag(name = "访问信息")
@Slf4j
public class VisitorApplyInfoController extends BaseController {

  @Resource
  IVisitorApplyInfoService visitorApplyInfoService;
  	/**
	 * 详情
	 */
	@PostMapping(NovaCRUDMethodConstant.NOVA_WEB_GETONE)
	@Operation(summary = "详情")
	public R<VisitorApplyInfoVO> getOne(@RequestBody VisitorApplyInfoDTO visitorApplyInfoDTO) {
        VisitorApplyInfoEntity entity = new VisitorApplyInfoEntity();
        BeanUtil.copyProperties(visitorApplyInfoDTO, entity);
		VisitorApplyInfoEntity detail = visitorApplyInfoService.getOne(Condition.getQueryWrapper(entity));
		return R.data(VisitorApplyInfoWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 代码自定义代号
	 */
	@GetMapping(NovaCRUDMethodConstant.NOVA_WEB_PAGE)
  @Operation(summary = "分页查询")
	public R getPage(VisitorApplyInfoQuery query, QueryContext queryContext) {
		IPage<VisitorApplyInfoEntity> pages = visitorApplyInfoService.page(Condition.getPage(queryContext), Condition.getQueryWrapper(query, queryContext,VisitorApplyInfoEntity.class));
		return R.data(VisitorApplyInfoWrapper.build().pageVO(pages));
	}

	/**
	 * 新增 代码自定义代号
	 */
	@PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVE)
	@Operation(summary = "新增")
	public R save(@RequestBody VisitorApplyInfoDTO visitorApplyInfoDTO) {
        VisitorApplyInfoEntity entity = new VisitorApplyInfoEntity();
        BeanUtil.copyProperties(visitorApplyInfoDTO, entity);
		return R.status(visitorApplyInfoService.save(entity));
	}

	/**
	 * 修改 代码自定义代号
	 */
	@PostMapping(NovaCRUDMethodConstant.NOVA_WEB_UPDATE)
	@Operation(summary = "修改")
	public R update(@RequestBody VisitorApplyInfoDTO visitorApplyInfoDTO) {
        VisitorApplyInfoEntity entity = new VisitorApplyInfoEntity();
        BeanUtil.copyProperties(visitorApplyInfoDTO, entity);
		return R.status(visitorApplyInfoService.updateById(entity));
	}

	/**
	 * 新增或修改 代码自定义代号
	 */
	@PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVEORUPDATE)
	@Operation(summary = "新增或修改")
	public R saveOrUpdate(@RequestBody VisitorApplyInfoDTO visitorApplyInfoDTO) {
        VisitorApplyInfoEntity entity = new VisitorApplyInfoEntity();
        BeanUtil.copyProperties(visitorApplyInfoDTO, entity);
		return R.status(visitorApplyInfoService.saveOrUpdate(entity));
	}


	/**
	 * 删除 代码自定义代号
	 */
	@PostMapping(NovaCRUDMethodConstant.NOVA_WEB_REMOVE)
	@Operation(summary = "逻辑删除")
	public R remove(@RequestParam String ids) {
		return R.status(visitorApplyInfoService.deleteLogic(Func.toLongList(ids)));
	}
  
    /**
	 * 物理删除，不可恢复
	 */
   @Operation(summary = "物理删除")
   @DeleteMapping(NovaCRUDMethodConstant.NOVA_WEB_DELETE)
   public R delete(@RequestParam String ids){
     return R.status(visitorApplyInfoService.deletePhysics(Func.toLongList(ids)));
   }
}
